Validate Data

Validate Field Value Immediately

Description
This customization validates a column as soon as the application user changes the value of a field. The customization performs validation on a particular column in an editable record to ensure that the value is appropriate. It performs validation by overriding the Validate() method in the record control class. If a value is invalid, Validate() method throws an exception and does not updated the record.
Variables
RecordControl
Select a record control
Validate Field Control
Select the field that you want to validate.
Applies to
RecordControl class
Code
 
''' 
''' This handler sets the AutoPostBack property of ${Validate Field}'s TextBox to True such
''' that the TextChanged handler is called when the value is changed.
''' 
''' The object that raised the init event.
''' The object that contains the event data of the init event.
Private Sub ValidateField_Init(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles MyBase.Init    
    AddHandler Me.${Validate Field Control}.TextChanged, AddressOf ${Validate Field Control}_TextChanged    
    Me.${Validate Field Control}.AutoPostBack = True  
End Sub
     
Applies to
RecordControl class
Code
 
''' 
''' This handler validates the page whenever the text in the ${Validate Field Control} TextBox changes.
''' The TextChanged handler is called when the value is changed.
''' 
Private Sub ${Validate Field Control}_TextChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) 
    Try
        Validate()
    Catch ex As Exception
		
		' Exception thrown by the Validate() sub is caught here.	
        ' Report the error message to the user.
        Utils.MiscUtils.RegisterJScriptAlert(Me, "UNIQUE_SCRIPTKEY","${Validate Field Control} cannot be empty ")
    End Try
End Sub


''' 
''' Override the Validate() method. Add your validation logic here.
''' If the value of ${Validate Field Control} is not valid
''' then throw an exception. The exception is caught in the ${Validate Field Control}_TextChanged
''' event handler and it calls RegisterJScriptAlert to report the error message to the user.
''' Throwing an exception in Validate() sub ensures that the record will not be saved. If you do not throw an exception
''' record will be saved. You can also validate other fields in the Validate() sub.
''' In this customization ${Validate Field Control}_TextChanged will report an error message to the user
''' if an exception is thrown by the Validate method. After the ${Validate Field Control}_TextChanged event
''' when the user clicks on the save button, the exception thrown by the Validate() sub will get caught
''' by the SaveButton_Click handler, which will call the RegisterJScriptAlert to report the error message to the user.
''' 
Public Overrides Sub Validate()
	MyBase.Validate()
	
    ' Add validation logic here
    If (Me.${Validate Field Control}.Text = "") Then    
        Throw New Exception
    End If
End Sub 

     

Terms of Service Privacy Statement